package com.kuanter.kuanterauto.website;


import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kuanter.kuanterauto.R;
import com.kuanter.kuanterauto.baseui.BaseActivity_NoBar;
import com.kuanter.kuanterauto.chexian.ChexianActivity;
import com.kuanter.kuanterauto.constants.MainConstants;
import com.kuanter.kuanterauto.utils.ImageLoader;
import com.umeng.analytics.MobclickAgent;

public class WebSiteDetailActivity extends BaseActivity_NoBar{
	
	Button btTopLeft_wd=null;
	RelativeLayout bt_webSite_getRoute = null;
	RelativeLayout bt_webSite_call = null;
	
	private ImageLoader mImageLoader=null;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.websitedetail);
		
		Bundle bundle = this.getIntent().getExtras();
		mImageLoader=new ImageLoader(this);
        
        /*获取Bundle中的数据，注意类型和key*/
        String shopName = bundle.getString("shopName");
        String shopAddress = bundle.getString("shopAddress");
        String queue = bundle.getString("queue");
        String bigcarPoint = bundle.getString("bigcarPoint");
        String bigcarPrice = bundle.getString("bigcarPrice");
        String smallcarPoint = bundle.getString("smallcarPoint");
        String smallcarPrice = bundle.getString("smallcarPrice");
        String distance = bundle.getString("distance");
        String phone = bundle.getString("phone");
        String shopImage = bundle.getString("shopImage");
//        System.out.println(smallcarPoint+"-"+smallcarPrice+"-"+bigcarPoint+"-"+bigcarPrice);
        
        TextView shopNameView = (TextView) findViewById(R.id.tv_webSite_shopName);
        shopNameView.setText(shopName);
        
        ImageView webSiteImage = (ImageView) findViewById(R.id.iv_webSite_image);
        System.out.println(MainConstants.HOST+shopImage);
        mImageLoader.DisplayImage(MainConstants.HOST+shopImage, webSiteImage, false);
        TextView shopAddressView = (TextView) findViewById(R.id.tv_webSite_address);
        shopAddressView.setText(shopAddress);
        
        TextView shopPhone = (TextView) findViewById(R.id.tv_webSite_phone);
        shopPhone.setText(phone);
        
        ImageView queueView = (ImageView) findViewById(R.id.iv_webSite_image2);
        
        
        if(queue.equals("1"))
        {
        	Bitmap bm = BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.di));
        	queueView.setImageBitmap(bm);
        }else if(queue.equals("2"))
        {
        	Bitmap bm = BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.zhong));
        	queueView.setImageBitmap(bm);
        }else if(queue.equals("3"))
        {
        	Bitmap bm = BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.gao));
        	queueView.setImageBitmap(bm);
        }
        
        
        TextView shopDistenceView = (TextView) findViewById(R.id.tv_webSite_juli);
        if(distance != null)
        	shopDistenceView.setText("距离："+distance+"KM");
        else
        	shopDistenceView.setText("距离：无法定位当前位置");
        
        TextView tv_webSite_bigcarpoint = (TextView) findViewById(R.id.tv_webSite_bigcarpoint);
        tv_webSite_bigcarpoint.setText(bigcarPoint);
        TextView tv_webSite_bigcarprice = (TextView) findViewById(R.id.tv_webSite_bigcarprice);
        tv_webSite_bigcarprice.setText(bigcarPrice);
        
        TextView tv_webSite_smallcarpoint = (TextView) findViewById(R.id.tv_webSite_smallcarpoint);
        tv_webSite_smallcarpoint.setText(smallcarPoint);
        TextView tv_webSite_smallcarprice = (TextView) findViewById(R.id.tv_webSite_smallcarprice);
        tv_webSite_smallcarprice.setText(smallcarPrice);
        
        btTopLeft_wd=(Button) findViewById(R.id.btTopLeft_wd);
        btTopLeft_wd.setOnClickListener(this);
        bt_webSite_getRoute= (RelativeLayout) findViewById(R.id.bt_webSite_getRoute);
        bt_webSite_getRoute.setOnClickListener(this);
        bt_webSite_call= (RelativeLayout) findViewById(R.id.bt_webSite_call);
        bt_webSite_call.setOnClickListener(this);
		}
	
    
	
	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.btTopLeft_wd:
			finish();
			break;
		case R.id.bt_webSite_getRoute:
			Bundle bundle = new Bundle();
			bundle.putString("xCoordinates", this.getIntent().getExtras().getString("xCoordinates"));
			bundle.putString("yCoordinates", this.getIntent().getExtras().getString("yCoordinates"));
			qStartActivity(WebSiteRouteActivity.class, bundle);
//			Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://ditu.google.cn/maps?hl=zh&mrt=loc&q="+this.getIntent().getExtras().getString("yCoordinates")+","+this.getIntent().getExtras().getString("xCoordinates")+"("+this.getIntent().getExtras().getString("shopName")+")"));
//			startActivity(i);
//			Uri mUri = Uri.parse("geo:"+this.getIntent().getExtras().getString("yCoordinates")+","+this.getIntent().getExtras().getString("xCoordinates")+"?q="+this.getIntent().getExtras().getString("shopName"));
//			Intent mIntent = new Intent(Intent.ACTION_VIEW,mUri);
//			startActivity(mIntent);
			
			break;
		case R.id.bt_webSite_call:
			if(this.getIntent().getExtras().getString("phone").length()>0)
			{
				final String tel = this.getIntent().getExtras().getString("phone");
				AlertDialog.Builder builder = new AlertDialog.Builder(
						WebSiteDetailActivity.this);
				builder.setTitle(tel);
				builder.setPositiveButton("呼叫",
						new DialogInterface.OnClickListener() {

							public void onClick(DialogInterface arg0, int arg1) {
								WebSiteDetailActivity.this.call(tel);
							}
						});

				builder.setNegativeButton("取消",
						new DialogInterface.OnClickListener() {

							public void onClick(DialogInterface arg0, int arg1) {
							}
						});

				builder.create().show();
			}
			break;
			
		}
	}
	
	@Override
	protected void onResume() {
		MobclickAgent.onResume(this);
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		MobclickAgent.onPause(this);
		super.onPause();
	}

	

}
